package com.business.system.controller;
import com.business.system.service.IAttentionService;
import com.business.system.service.IShopService;
import com.business.system.vo.*;
import com.common.entity.Attention;
import com.common.entity.Shop;
import com.common.untils.CommonResult;
import io.swagger.models.auth.In;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author pgx
 * @since 2022-08-31
 */
@RestController
@RequestMapping("/system/shop")
public class ShopController {
    @Autowired
    private IShopService iShopService;
    @Autowired
    private IAttentionService iAttentionService;
    //查询关注的店铺
    @PostMapping("/selectAttention/{sid}")
    public CommonResult selectAttention(@PathVariable("sid") Integer sid){
        System.out.println(sid+"----");
        return iAttentionService.selectDP(sid);
    }
    //查询关注的店铺
    @PostMapping("/show/{currentPage}/{pageSize}")
    public CommonResult show(@PathVariable Integer currentPage, @PathVariable Integer pageSize, HttpServletRequest request){
        String hometoken = request.getHeader("hometoken");
        return iAttentionService.select(currentPage,pageSize,hometoken);
    }
    //取消关注
    @PostMapping("/deleteAttention/{sid}")
    public CommonResult deleteAttention(@PathVariable Integer sid){
        return iAttentionService.delete(sid);
    }
    //关注店铺
    @PostMapping("/attention/{sid}/{name}")
    public CommonResult attention(@PathVariable Integer sid,@PathVariable String name,HttpServletRequest request){
        String hometoken = request.getHeader("hometoken");
        return iAttentionService.inset(sid,name,hometoken);
    }
    //页面回显
    @PostMapping("findAllShop")
    public CommonResult findAllShop(@RequestBody ShopVo shopVo){
        return iShopService.findAllShop(shopVo);
    }
    //详细信息
    @PostMapping("detailedMsg/{id}")
    public CommonResult detailedMsg(@PathVariable Integer id){
        return iShopService.detailedMsg(id);
    }
    //修改店铺状态
    @PostMapping("editStart/{start}/{id}")
    public CommonResult editStart(@PathVariable Integer start,@PathVariable Integer id){
       return iShopService.editStart(start,id);
    }
    //根据商家id查询店铺信息
    @PostMapping("findByIdShopMsg/{id}")
    public CommonResult findByIdShopMsg(@PathVariable Integer id){
        return iShopService.findByIdShopMsg(id);
    }
    //根据商家id查询店铺信息
    @PostMapping("selectShopMsgByBid")
    public CommonResult selectShopMsgByBid(HttpServletRequest request){
        String homeToken = request.getHeader("homeToken");
        return iShopService.selectShopMsgByBid(homeToken);
    }
    //根据商家id修改店铺信息
    @PostMapping("updateShopMsgByBid")
    public CommonResult updateShopMsgByBid(HttpServletRequest request, @RequestBody ShopAndBussinessVo shopAndBussinessVo){
        String homeToken = request.getHeader("homeToken");
        return iShopService.updateShopMsgByBid(homeToken,shopAndBussinessVo);
    }
    //通过中间表ID查找该商品
    @PostMapping("findByZidAll/{id}")
    public CommonResult findByZidAll(@PathVariable Integer id){
        return iShopService.findByZidAll(id);
    }
    //通过店铺id查询店铺信息
    @PostMapping("findByShopId/{id}")
    public CommonResult findByShopId(@PathVariable Integer id){
        return iShopService.findByShopId(id);
    }
    // 通过店铺id 查询当前店铺的所有商品
    @PostMapping("findByshopIdAllGoods/{pageCurrent}/{pageSize}/{shopId}")
    public CommonResult findByshopIdAllGoods(@PathVariable Integer pageCurrent, @PathVariable Integer pageSize, @PathVariable Integer shopId, @RequestBody Map<String,Object> names){
        return iShopService.findByshopIdAllGoods(pageCurrent,pageSize,shopId,names);
    }
    //根据店铺id查询店铺商品
    @PostMapping("findGoodsBySid")
    public CommonResult findGoodsBySid(HttpServletRequest request,@RequestBody GoodsVo goodsVo){
        String homeToken = request.getHeader("homeToken");
        return iShopService.findGoodsBySid(homeToken,goodsVo);
    }
    //根据商品id修改店铺商品状态
    @PostMapping("updateGoodsState/{state}/{id}")
    public CommonResult updateGoodsState(@PathVariable Integer state,@PathVariable Integer id){
        return iShopService.updateGoodsState(state,id);
    }
    //入店接口
    @PostMapping("addGoodsToShop/{gid}")
    public CommonResult addGoodsToShop(@PathVariable String gid, @RequestBody GoodsShopVo goodsShopVo,HttpServletRequest request){
        String homeToken = request.getHeader("homeToken");
        return iShopService.addGoodsToShop(gid,goodsShopVo,homeToken);
    }
}
